package com.dict.mybatis.lab.mapper;


import com.dict.mybatis.lab.entity.User;
import com.dict.mybatis.lab.entity.User2;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 用户表(User)表数据库访问层
 *
 * @author lzqing
 * @since 2023-03-22 10:46:14
 */
@Repository
public interface UserMapper {

    @Select("SELECT * FROM t_user")
    @Results({@Result(property = "sex", column = "sex"), @Result(property = "name", column = "name")})
    List<User> getAll();

    @Select("SELECT * FROM t_user WHERE id = #{id}")
    @Results({@Result(property = "sex", column = "sex"), @Result(property = "name", column = "name")})
    User getOne(Long id);

    @Insert("INSERT INTO t_user(name,sex,phone) VALUES(#{name}, #{sex,typeHandler=org.apache.ibatis.type.EnumTypeHandler}, #{phone})")
    void insert(User user);

    @Update("UPDATE t_user SET name=#{name},sex=#{sex},phone= #{phone} WHERE id =#{id}")
    void update(User user);

    @Delete("DELETE FROM t_user WHERE id =#{id}")
    void delete(Long id);


    List<User> findUsers();

    User findUserById(Long id);

    Long insertUer(User user);

    Long insertUUID(User2 user2);

}
